<%--
  Created by IntelliJ IDEA.
  User: 武露斌
  Date: 2021/10/25
  Time: 9:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="../../jquery-ui-1.10.4.custom/js/jquery-1.8.2.min.js"></script>
    <link rel="stylesheet" href="../../jquery-ui-1.10.4.custom/css/css.css">

    <script src="../../jquery-ui-1.10.4.custom/js/jquery-1.10.2.js"></script>
    <script src="../../jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js"></script>
    <link rel="stylesheet" href="../../jquery-ui-1.10.4.custom/css/base/jquery-ui-1.10.4.custom.min.css">
</head>
<body>

<form>
       源账户名称<input type="text" id="yname"> 源账号:<input type="text" id="yzh"><br>
       目标账户名称<input type="text" id="mname"> 目标账户<input type="text" id="mzh"><br>

   财务日期:<input type="text" name="cdate"><br>

   科目编号<input type="text" name="kid"><br>
   科目<input type="text" name="km"><br>
   摘要<input type="text" name="bz"><br>
   借方<input type="text" name="qf"><br>
   贷方<input type="text" name="df"><br>
   余额<input type="text" name="yue"><br>
    原账号：<select name="yid">
    <option value="">请选择</option>
</select>
</form>
<input type="button" value="添加" onclick="add()">

</body>
</html>
<script>

    $.post(
        "listlo.do",
        function (data) {
            for (let i = 0; i <data.length ; i++) {
                $("[name='yid']").append(' <option value="'+data[i].lid+'">'+data[i].yname+'</option>')
            }
        }
    )


    var namearray = new Array();
    var qbarray1 = new Array();

    $.ajax({
        url: "listlo.do",
        type: "post",
        dataType: "json",
        success:function (data) {
            for (let i = 0; i <data.length ; i++) {
                namearray.push(data[i].yname)
                namearray.push(data[i].mname)
                qbarray1.push(data[i])
            }
        }
    })


    $("#yname").autocomplete({
        source:namearray,messages:{
            noResults:"",
            results:function () {
            }
        },
        select:function (event,ui) {
            let yname=ui.item.value
            for (let i = 0; i <qbarray1.length ; i++) {
                if (yname==qbarray1[i].yname){
                    $("#yzh").val(qbarray1[i].yzh)
                }
            }
        }
    })

    $("#mname").autocomplete({
        source:namearray,messages:{
            noResults:"",
            results:function () {
            }
        },
        select:function (event,ui) {
            let mname=ui.item.value
            for (let i = 0; i <qbarray1.length ; i++) {
                if (mname==qbarray1[i].mname){
                    $("#mzh").val(qbarray1[i].mzh)
                }
            }
        }
    })



    function add() {

        var a=$("[name='qf']").val()
        var b=$("[name='df']").val()
        $("[name='yue']").val(a-b)

        if ($("[name='cdate']").val().length==0){
            alert("日期不能为空")
            return false;
        }
        if ($("[name='kid']").val().length==0){
            alert("科目编号不能为空")
            return false;
        }

        if ($("[name='km']").val().length==0){
            alert("科目不能为空")
            return false;
        }
        if ($("[name='bz']").val().length==0){
            alert("摘要不能为空")
            return false;
        }
        if ($("[name='qf']").val().length==0){
            alert("借方不能为空")
            return false;
        }
        if ($("[name='df']").val().length==0){
            alert("贷方不能为空")
            return false;
        }
        if ($("[name='yid']").val().length==0){
            alert("原账号不能为空")
            return false;
        }





        var formData = new  FormData($("form")[0]);
        $.ajax({
            url:"add.do",
            data:formData,
            type:"post",
            dataType:"json",
            success:function (data) {
                if (data>0){
                    alert("添加成功")
                    location="list.do"
                }else{
                    alert("添加失败")
                }
            },processData:false,contentType:false
        })
    }

</script>























